#include<iostream>
#include<map>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef pair<int,int> PII;
PII sum[1100];
bool cmp(PII a,PII b)
{
	return a.x>b.x;
}
int main()
{
	int N;
	cin>>N;
	while(N--)
	{
		int u,v,w;
		scanf("%d-%d %d",&u,&v,&w);
		sum[u].x+=w;
		sum[u].y=u;
	}
	sort(sum,sum+1001,cmp);
	cout<<sum[0].y<<' '<<sum[0].x<<endl;
	return 0;
}
